#!/bin/bash

echo "打包文件"
pnpm build:prod
echo "传输文件（排除 pages 目录）"
# 创建临时目录，排除 pages 目录
mkdir -p ./temp_dist
rsync -av --exclude 'pages' --exclude 'themes' ./dist-prod/ ./temp_dist/

echo "使用 scp 传输文件"
scp -r ./temp_dist/** root@113.44.67.181:/opt/deploy/ui
#scp -r -i /c/Users/Administrator/.ssh/id_rsa  ./temp_dist/** root@113.44.67.181:/opt/deploy/ui
#rsync -avz --progress ./temp_dist/** root@113.44.67.181:/opt/deploy/ui

echo "删除临时目录"
rm -rf ./temp_dist

# 检查 scp 命令的返回状态
if [ $? -eq 0 ]; then
    echo "部署成功"
else
    echo "部署失败，scp 命令执行出错"
    exit 1
fi

# 连接服务器 使用公钥免密登录
# ssh -i /c/Users/Administrator/.ssh/id_rsa 'root@113.44.67.181'
